package com.example.demo02.controller.Swagger;

import com.example.demo02.entity.Goods;
import com.example.demo02.dao.GoodsDao;
import com.example.demo02.utils.ResponseData;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "商品信息接口")
@RestController
@RequestMapping("/Goods")
public class GoodsController {
    @GetMapping("/{id}")
    public ResponseData getGoods(@PathVariable int id) {
        Goods goods = GoodsDao.findGoodsById(id);
        return new ResponseData("200", null, true, goods);
    }

    @GetMapping("")
    public ResponseData getAllGoods() {
        Map<Integer, Goods> goodsMap = GoodsDao.findAllGoods();
        return new ResponseData("200", null, true, goodsMap);
    }

    @PutMapping("")
    public ResponseData updateGoods(@RequestBody Goods goods) {
        GoodsDao.updateGoods(goods);
        return new ResponseData("200", null, true, null);
    }

    @PostMapping("")
    public ResponseData addGoods(@RequestBody Goods goods) {
        GoodsDao.addGoods(goods);
        return  new ResponseData("200", null, true, null);
    }

    @DeleteMapping("/{id}")
    public ResponseData deleteGoods(@PathVariable int id) {
        GoodsDao.deleteGoods(id);
        return new ResponseData("200", null, true, null);
    }
}
